const code = '2+3'
const tokens1 = code.split('').filter(item => !!item.trim())


function tokenPeek(tokens: string[]) {
    return tokens[1] || null
}

function tokenRead(tokens: string[]) {
    return tokens.splice(0, 1)
}

function isInt(token: string) {
    return /\d/.test(token)
}

// 加法表达式
// int
// plus

const node = null;
const nodes = []
let token = tokenPeek(tokens1)
if (token != null && isInt(token)) {   //匹配Int

    token = tokenRead(tokens1);      //消耗掉int
    let nextToken = tokenPeek(tokens1)
    if (nextToken && nextToken == '+') { //匹配标识符
        token = tokenRead(tokens1);  //消耗掉标识符
        token = tokenPeek(tokens1)
        if (token && isInt(token)){
            token = tokenRead(tokens1);
        }
        //创建当前节点，并把变量名记到AST节点的文本值中，
        //这里新建一个变量子节点也是可以的
        node = new SimpleASTNode(ASTNodeType.IntDeclaration, token.getText());
        token = tokens.peek();  //预读
        if (token != null && token.getType() == TokenType.Assignment) {
            tokens.read();      //消耗掉等号
            SimpleASTNode
            child = additive(tokens);  //匹配一个表达式
            if (child == null) {
                throw new Exception("invalide variable initialization, expecting an expression");
            } else {
                node.addChild(child);
            }
        }
    } else {
        throw new Exception("variable name expected");
    }
}
